package com.hurl.waguji.biz.collect;

import java.util.List;

import com.hurl.waguji.base.SqlReader;
import com.hurl.waguji.base.dao.HibernateDao;
import com.hurl.waguji.base.dao.HibernateService;
import com.hurl.waguji.persistence.SelectOptionsBO;

public class UpdateProfileProcess implements CollectProcess{

	@Override
	public void execute() {
		HibernateDao dao = HibernateService.getDao();

		GpdmIterator it = new GpdmIterator();
		it.addHandler(new ProfileHandler());
		it.addHandler(new ProfileCwHandler());
		it.start();
		updateSelectOptions();
		
		dao.flush();
		dao.clear();
	}

	/**
	 * 更新表t_select_options
	 */
	private static void updateSelectOptions(){
		HibernateDao dao = HibernateService.getDao();
		
		//gs_qy_mc
		List<String> list = (List<String>)dao.queryBySQL(SqlReader.getSql("SQL12042101")).list();
		String fw = "";
		if(list!=null && !list.isEmpty()){
			for(int i=0;i<list.size();i++){
				if(i==0){
					fw+=list.get(0);
				}else{
					fw+=","+list.get(i);
				}
			}
		}
		SelectOptionsBO options = dao.get(SelectOptionsBO.class, "gs_qy_mc");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		
		//gs_sshy_mc
		list = (List<String>)dao.queryBySQL(SqlReader.getSql("SQL12042102")).list();
		fw = "";
		if(list!=null && !list.isEmpty()){
			for(int i=0;i<list.size();i++){
				if(i==0){
					fw+=list.get(0);
				}else{
					fw+=","+list.get(i);
				}
			}
		}
		options = dao.get(SelectOptionsBO.class, "gs_sshy_mc");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		
		//gs_ssrq
		Object[] datelist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042201")).list().get(0);
		fw = "";
		if(datelist!=null && datelist.length!=0){
			fw=(String)datelist[0]+","+(String)datelist[1];
		}
		options = dao.get(SelectOptionsBO.class, "gs_ssrq");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);

		//gs_fxjg
		Object[] numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042202")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "gs_fxjg");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//gs_fxsyl
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042203")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "gs_fxsyl");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//hq_zxj
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042204")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "hq_zxj");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//hq_zdf
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042205")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "hq_zdf");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//hq_cje
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042206")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "hq_cje");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//hq_hs
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042207")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "hq_hs");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//hq_zf
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042208")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "hq_zf");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//gd_gdrs
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042209")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "gd_gdrs");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//gbjg_gfzs
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042210")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "gbjg_gfzs");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//lrb_jlr
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042211")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "lrb_jlr");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//zcfzb_fzhj
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042212")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "zcfzb_fzhj");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//lrb_yysr
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042213")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "lrb_yysr");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//zcfzb_zczj
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042214")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "zcfzb_zczj");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		//zcfzb_syzqyhj
		numlist = (Object[])dao.queryBySQL(SqlReader.getSql("SQL12042215")).list().get(0);
		fw = "";
		if(numlist!=null && numlist.length!=0){
			fw=numlist[0]+","+numlist[1];
		}
		options = dao.get(SelectOptionsBO.class, "zcfzb_syzqyhj");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		
		//gplx_mc
		list = (List<String>)dao.queryBySQL(SqlReader.getSql("SQL12050601")).list();
		fw = "";
		if(list!=null && !list.isEmpty()){
			for(int i=0;i<list.size();i++){
				if(i==0){
					fw+=list.get(0);
				}else{
					fw+=","+list.get(i);
				}
			}
		}
		options = dao.get(SelectOptionsBO.class, "gplx_mc");
		if(options!=null){
			options.setFw(fw);
		}
		dao.update(options);
		dao.flush();
		dao.clear();
		return;
	}

}
